package com.mikufufu.blog.controller.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mikufufu.blog.common.entity.AjaxResult;
import com.mikufufu.blog.model.dto.api.PicturePageParam;
import com.mikufufu.blog.model.entity.Picture;
import com.mikufufu.blog.model.vo.api.PictureVO;
import com.mikufufu.blog.service.PictureService;
import com.mikufufu.blog.utils.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "图片")
@RestController
@RequestMapping("/picture")
public class PictureController {

    @Autowired
    private PictureService pictureService;

    @ApiOperation(value = "分页查询相册列表", notes = "用于获取相册列表")
    @PostMapping("/page")
    public AjaxResult<IPage<PictureVO>> page(@RequestBody @Validated PicturePageParam param){
        return AjaxResult.data(pictureService.getPicturePage(param));
    }

    @ApiOperation(value = "获取相册详情", notes = "获取相册详情")
    @GetMapping("/detail")
    public AjaxResult<PictureVO> detail(Integer id) {
        Picture picture = pictureService.getById(id);
        return AjaxResult.data(BeanUtil.copy(picture, PictureVO.class));
    }
}
